use std::io::{Error, ErrorKind};

fn main(){
    let mut ok = Ok(0);
    while let Ok(i) = ok {
        if i>9 {
            println!("the value of i is {}, quit the loop", i);
            ok = Err(Error::new(ErrorKind::Other, "oh no!"));
        }else {
            println!("the value of i is {}",i);
            ok = Ok(i+1);
        }
    }
	
	//自定义类型
	let mut enum_value = Message::Move{x:0,y:0};
	while let Message::Move{x,y}= enum_value {
	   enum_value.call();
	   
	   if x>9 {
		   enum_value=Message::Quit;
	   }else {
		  	   let new_x = x+1;
		   let new_y = y+1;
		   enum_value = Message::Move{x:new_x,y:new_y}; 
	   }	   
    }
}


#[derive(PartialEq)]
enum Message {
    Quit,                       // 没有附加数据
    Move { x: i32, y: i32 },    // 包含匿名结构体
}

impl Message {
	fn call(&self) {
		match self {
			Message::Quit=> {println!("quit!")},
			Message::Move{x,y}=>{println!("Move the position x={},y={}",x,y)},
		}
	}
}

